<template>
  <div class="app-container">
    <el-card class="operate-container" shadow="never">
      <i class="el-icon-tickets"></i>
      <span>数据列表</span>
      <el-button
        class="btn-add"
        @click="addCase()"
        size="mini">
        添加
      </el-button>
    </el-card>
    <div class="table-container">
      <el-table ref="brandTable"
                :data="list"
                style="width: 100%"
                @selection-change="handleSelectionChange"
                v-loading="listLoading"
                border>
        <el-table-column type="index" width="60" align="center"></el-table-column>
        <!-- <el-table-column type="index" label="案例编号" width="100" align="center">
          <template slot-scope="scope">
            {{scope.row.caseId}}
          </template>
        </el-table-column> -->
        <el-table-column label="封面图" width="120" align="center">
          <template slot-scope="scope">
            <img style="height: 80px;width: 100px;" :src="scope.row.coverPic">
          </template>
        </el-table-column>
        <el-table-column label="案例标题" align="center">
          <template slot-scope="scope">{{scope.row.title}}</template>
        </el-table-column>
        <el-table-column label="案例户型" align="center">
          <template slot-scope="scope">{{scope.row.houseType}}</template>
        </el-table-column>
        <el-table-column label="案例类型" align="center">
          <template slot-scope="scope">{{scope.row.type}}</template>
        </el-table-column>
        <el-table-column label="操作" width="200" align="center">
          <template slot-scope="scope">
            <el-button
              size="mini"
              @click="handleUpdate(scope.$index, scope.row)">编辑
            </el-button>
            <el-button
              size="mini"
              type="danger"
              @click="handleDelete(scope.$index, scope.row)">删除
            </el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>

    <div class="pagination-container">
      <el-pagination
        background
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        layout="total, sizes,prev, pager, next,jumper"
        :page-size="listQuery.pageSize"
        :page-sizes="[5,10,15]"
        :current-page.sync="listQuery.pageNo"
        :total="total">
      </el-pagination>
    </div>
  </div>
</template>
<script>
  import {findCaseList,deleteCase} from '@/api/case'
  export default {
    name: 'caseList',
    data() {
      return {
        operateType: null,
        listQuery: {
          pageNo: 1,
          pageSize: 10
        },
        testUrl:'https://img2.baidu.com/it/u=391432076,2333879031&fm=26&fmt=auto&gp=0.jpg',
        list: null,
        total: null,
        listLoading: true,
        multipleSelection: []
      }
    },
    created() {
      this.getList();
    },
    methods: {
      getList() {
        this.listLoading = true;
        findCaseList(this.listQuery).then(response => {
          this.listLoading = false;
          this.list = response.data.list;
          this.total = response.data.total;
          this.totalPage = response.data.totalPage;
          this.pageSize = response.data.pageSize;
        });
      },
      handleSelectionChange(val) {
        this.multipleSelection = val;
      },
      handleUpdate(index, row) {
        this.$router.push({
          path: '/bus/updateCase',
          query: {id: row.caseId}
        })
      },
      handleDelete(index, row) {
        this.$confirm('是否要删除该案例', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          deleteCase(row.caseId).then(response => {
            this.$message({
              message: '删除成功',
              type: 'success',
              duration: 1000
            });
            this.getList();
          });
        });
      },
      getProductList(index, row) {
        console.log(index, row);
      },
      getProductCommentList(index, row) {
        console.log(index, row);
      },
      handleSizeChange(val) {
        this.listQuery.pageNo = 1;
        this.listQuery.pageSize = val;
        this.getList();
      },
      handleCurrentChange(val) {
        this.listQuery.pageNo = val;
        this.getList();
      },
      searchBrandList() {
        this.listQuery.pageNo = 1;
        this.getList();
      },
      addCase() {
        this.$router.push({path: '/bus/addCase'})
      }
    }
  }
</script>

<style rel="stylesheet/scss" lang="scss" scoped>

</style>


